﻿using System;
using ThangNM_LIB.FUNC;

namespace ThangNM.UserControl
{
    public partial class ToolBarUC : System.Web.UI.UserControl
    {
        #region "Properties & Event"
        public delegate void CustomerEventHandler(object sender, CustomerEventArgs args);
        public event CustomerEventHandler EventButtonToolBar;
        public event CustomerEventHandler EventSelectChange;
        #endregion

        #region "Common"
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void setView(Int16 iFuncType)
        {
            pnlToolBar4List.Visible = false;
            pnlToolBar4Detail.Visible = false;
            btnListRefresh.Visible = false;
            btnListInsert.Visible = false;
            btnListDelete.Visible = false;
            btnListExport.Visible = false;
            btnListImport.Visible = false;
            lbtnDetailBack.Visible = false;
            btnDetailInsert.Visible = false;
            btnDetailUpdate.Visible = false;
            btnDetailDelete.Visible = false;
            btnDetailReset.Visible = false;
            btnDetailPreview.Visible = false;
            btnDetailClone.Visible = false;
            btnDetailSaveAdd.Visible = false;
            btnDetailPrint.Visible = false;
            switch (iFuncType)
            {
                case ConstEx.FunctionNew.LIST:
                    pnlToolBar4List.Visible = true;
                    btnListRefresh.Visible = true;
                    btnListInsert.Visible = true;
                    btnListDelete.Visible = true;
                    btnListExport.Visible = true;
                    btnListImport.Visible = true;
                    break;
                case ConstEx.FunctionNew.DETAIL_I:
                    pnlToolBar4Detail.Visible = true;
                    lbtnDetailBack.Visible = true;
                    btnDetailInsert.Visible = true;
                    btnDetailReset.Visible = true;
                    btnDetailPreview.Visible = true;
                    btnDetailSaveAdd.Visible = true;
                    break;
                case ConstEx.FunctionNew.DETAIL_V:
                    pnlToolBar4Detail.Visible = true;
                    lbtnDetailBack.Visible = true;
                    btnDetailUpdate.Visible = true;
                    btnDetailDelete.Visible = true;
                    btnDetailReset.Visible = true;
                    btnDetailPreview.Visible = true;
                    btnDetailClone.Visible = true;
                    btnDetailPrint.Visible = true;
                    break;
            }
            btnListExport.Visible = false;
            btnListImport.Visible = false;
        }

        protected void setEvent(Int16 _iType, String _sMessage, object _objEntity)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(_iType, _sMessage, _objEntity));
        }
        #endregion

        #region "List"
        public void BindData_DropDownList(object lst)
        {
            ddlListType.DataSource = lst;
            ddlListType.DataTextField = "Value";
            ddlListType.DataValueField = "Key";
            ddlListType.DataBind();
        }

        public void SetDefaultValue(object value)
        {
            try
            {
                ddlListType.SelectedValue = Convert.ToString(value);
            }
            catch { }
        }

        protected void ddlListType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (EventSelectChange != null)
                EventSelectChange(this, new CustomerEventArgs(ConstEx.FunctionNew.DEFAULT, ddlListType.SelectedValue, null));
        }

        protected void btnListRefresh_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.ListRefresh))
                setEvent(ConstEx.FunctionNew.ListRefresh, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnListInsert_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.ListInsert))
                setEvent(ConstEx.FunctionNew.ListInsert, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnListDelete_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.ListDelete))
                setEvent(ConstEx.FunctionNew.ListDelete, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnListExport_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.ListExport))
                setEvent(ConstEx.FunctionNew.ListExport, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnListImport_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.ListImport))
                setEvent(ConstEx.FunctionNew.ListImport, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }
        #endregion

        #region "Detail"
        protected void btnDetailInsert_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailInsert))
                setEvent(ConstEx.FunctionNew.DetailInsert, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnDetailUpdate_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailUpdate))
                setEvent(ConstEx.FunctionNew.DetailUpdate, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnDetailDelete_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailDelete))
                setEvent(ConstEx.FunctionNew.DetailDelete, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnDetailReset_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailReset))
                setEvent(ConstEx.FunctionNew.DetailReset, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnDetailPreview_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailPreview))
                setEvent(ConstEx.FunctionNew.DetailPreview, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void lbtnDetailBack_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailBack))
                setEvent(ConstEx.FunctionNew.DetailBack, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnDetailClone_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailClone))
                setEvent(ConstEx.FunctionNew.DetailClone, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnDetailSaveAdd_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailSaveAdd))
                setEvent(ConstEx.FunctionNew.DetailSaveAdd, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }

        protected void btnDetailPrint_Click(object sender, EventArgs e)
        {
            if (Security.CheckPermission(ConstEx.FunctionNew.DetailReport))
                setEvent(ConstEx.FunctionNew.DetailReport, null, null);
            else
                setEvent(ConstEx.FunctionNew.ACCESS_DENIAL, null, null);
        }
        #endregion
    }
}